package com.rambler.fileupload.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author suhao
 */
@Component
public class UploadServiceFactory {

    private final List<FileUploadService> fileUploadServices;

    @Autowired
    public UploadServiceFactory(List<FileUploadService> uploadServices) {
        this.fileUploadServices = uploadServices;
    }

    // 根据上传类型获取对应的上传服务
    public FileUploadService getService(String type) {
        return this.fileUploadServices.stream()
                .filter(s -> s.supports(type))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("不支持的上传类型: " + type));
    }

}
